package com.fr.report.web.ui;

import com.fr.base.background.Background;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONArray;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.web.Repository;
import com.fr.web.core.HTMLWriterUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ToolBar extends Widget
{
  protected List widgets = new ArrayList();
  private boolean isDefault = true;
  private Background background = null;

  public ToolBar()
  {
  }

  public ToolBar(Widget[] paramArrayOfWidget)
  {
    if (paramArrayOfWidget != null)
      this.widgets.addAll(Arrays.asList(paramArrayOfWidget));
  }

  public String getXType()
  {
    return "toolbar";
  }

  public boolean isEditor()
  {
    return false;
  }

  public String[] supportedEvents()
  {
    return new String[0];
  }

  public boolean isDefault()
  {
    return this.isDefault;
  }

  public void setDefault(boolean paramBoolean)
  {
    this.isDefault = paramBoolean;
  }

  public Background getBackground()
  {
    return this.background;
  }

  public void setBackground(Background paramBackground)
  {
    this.background = paramBackground;
  }

  public int getWidgetSize()
  {
    return ((this.widgets == null) ? 0 : this.widgets.size());
  }

  public Widget getWidget(int paramInt)
  {
    return ((Widget)this.widgets.get(paramInt));
  }

  public void addWidget(Widget paramWidget)
  {
    if (this.widgets == null)
      this.widgets = new ArrayList();
    this.widgets.add(paramWidget);
  }

  public Widget removeWidget(int paramInt)
  {
    if ((this.widgets == null) || (this.widgets.size() <= paramInt))
      return null;
    return ((Widget)this.widgets.remove(paramInt));
  }

  public void clearWidgets()
  {
    if (this.widgets != null)
      this.widgets.clear();
  }

  public JSONObject createJSONConfig(Repository paramRepository)
    throws JSONException
  {
    return createJSONConfig(null, paramRepository);
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    localJSONObject.put("disabled", (isDisabled()) ? "true" : "false");
    localJSONObject.put("items", createJSONComponents(paramRepository));
    if (!(this.isDefault))
      if (this.background != null)
        localJSONObject.put("toolbarbg", HTMLWriterUtils.jsonBackground(this.background, paramRepository));
      else
        localJSONObject.put("toolbarbg", "none");
    return localJSONObject;
  }

  private JSONArray createJSONComponents(Repository paramRepository)
    throws JSONException
  {
    JSONArray localJSONArray = new JSONArray();
    int i = 0;
    int j = this.widgets.size();
    while (i < j)
    {
      localJSONArray.put(((Widget)this.widgets.get(i)).createJSONConfig(null, paramRepository));
      ++i;
    }
    return localJSONArray;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ToolBar");
    int i = 0;
    int j = getWidgetSize();
    while (i < j)
    {
      ReportXMLUtils.writeXMLable(paramXMLPrintWriter, getWidget(i), "Widget");
      ++i;
    }
    if (!(isDefault()))
    {
      paramXMLPrintWriter.startTAG("IsDefault").textNode(String.valueOf(this.isDefault)).end();
      if (this.background != null)
        BaseXMLUtils.writeBackground(paramXMLPrintWriter, this.background);
    }
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
      clearWidgets();
    if (paramXMLableReader.isChildNode())
    {
      Object localObject;
      String str = paramXMLableReader.getTagName();
      if (str.equals("Widget"))
      {
        localObject = ReportXMLUtils.readWidget(paramXMLableReader);
        addWidget((Widget)localObject);
      }
      else if ("Background".equals(str))
      {
        setBackground(BaseXMLUtils.readBackground(paramXMLableReader));
      }
      else if ("IsDefault".equals(str))
      {
        localObject = null;
        if ((localObject = paramXMLableReader.getElementValue()) != null)
          setDefault(Boolean.valueOf((String)localObject).booleanValue());
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if ((paramObject == null) || (!(paramObject instanceof ToolBar)))
      return false;
    ToolBar localToolBar = (ToolBar)paramObject;
    return ((super.equals(paramObject)) && (ComparatorUtils.equals(this.widgets, localToolBar.widgets)) && (this.isDefault == localToolBar.isDefault) && (ComparatorUtils.equals(this.background, localToolBar.background)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ToolBar localToolBar = (ToolBar)super.clone();
    if (this.widgets != null)
    {
      localToolBar.widgets = new ArrayList(this.widgets.size());
      int i = 0;
      int j = this.widgets.size();
      while (i < j)
      {
        localToolBar.widgets.add(((Widget)this.widgets.get(i)).clone());
        ++i;
      }
    }
    if (this.background != null)
      localToolBar.background = ((Background)this.background.clone());
    return localToolBar;
  }
}